package com.zhangxu.basemvp.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;

import com.google.gson.Gson;
import com.zhangxu.basemvp.R;
import com.zhangxu.basemvp.bean.UserBean;
import com.zhangxu.basemvp.componecnt.DaggerLoginActivityComponecnt;
import com.zhangxu.basemvp.contract.LoginContract;
import com.zhangxu.basemvp.contractmodel.LoginContractModel;
import com.zhangxu.basemvp.presenter.LoginPresenterImpl;
import com.zhangxu.basemvp.utils.ToastUtil;

import java.util.HashMap;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Time:2019/4/18
 * Author:zhangxu
 */
public class TestLoginActivity extends AppCompatActivity implements LoginContract.View {
    @BindView(R.id.email)
    EditText et_email;
    @BindView(R.id.password)
    EditText et_password;
    @Inject
    LoginPresenterImpl loginPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        DaggerLoginActivityComponecnt.builder().
                loginContractModel(new LoginContractModel(this))
                .build().inject(this);
    }


    @Override
    public String getUserName() {
        return et_email.getText().toString();
    }

    @Override
    public String getPassWord() {
        return et_password.getText().toString();
    }

    @Override
    public void loginSuccess(UserBean user) {
        showMessage(new Gson().toJson(user));
        et_email.setText(user.getName());
        LoginActivity.actionStart(this);

    }

    @Override
    public void showMessage(String msg) {
        ToastUtil.showLongToast(this, msg);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void dismissLoading() {

    }

    @OnClick(R.id.email_sign_in_button)
    public void toLogin() {
        loginPresenter.login();


    }
}
